package com.jz.netthings.bloodsources.controller;


import com.jz.netthings.bean.system.JyRole;
import com.jz.netthings.bloodsources.bean.XyLink;
import com.jz.netthings.bloodsources.bean.XyRemind;
import com.jz.netthings.bloodsources.constant.BloodSourcesConstant;
import com.jz.netthings.bloodsources.service.XyRemindService;
import com.jz.netthings.bloodsources.utils.BloodSourcesDateUtils;
import com.jz.netthings.exception.AdscmSystemException;
import com.jz.netthings.security.utils.Token;
import com.jz.netthings.support.SimpleCoreResponse;
import com.jz.netthings.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 献浆提醒记录 前端控制器
 * </p>
 *
 * @author 张凡
 * @since 2019-08-03
 */
@RestController
@RequestMapping("/adscm/bloodSources/xyRemind")
public class XyRemindController {

    @Autowired
    XyRemindService xyRemindService;
    @RequestMapping("/queryByCondition")
    public SimpleCoreResponse queryByCondition( HttpServletRequest request,
                                                String overRemindTimeLess ,
                                                String overRemindTimeGreater ,
                                                String remindDateLess,
                                                String remindDateGreater,
                                                String remindNurseName,
                                                String remindProviderName,
                                                Integer remindStatus,
                                                String currentPage,
                                                String pageSize) throws AdscmSystemException {
        return  new SimpleCoreResponse("200","查询成功",xyRemindService.queryByCondition(request,overRemindTimeLess,overRemindTimeGreater,remindDateLess,remindDateGreater,remindNurseName,remindProviderName,remindStatus,currentPage,pageSize));
    }
    @RequestMapping("/updateXyRemindInfo")
    public SimpleCoreResponse updateXyRemindInfo(@RequestBody XyRemind xyRemind, HttpServletRequest request) throws AdscmSystemException, IOException {
        String tokenId = request.getParameter("tokenId");
        //计算处理用时差值
        if(xyRemind.getRemindStatus()!=null&&xyRemind.getRemindStatus()==1){
            Date initTime = xyRemind.getRemindDate();
            Date overTime = xyRemind.getOverRemindTime();
            //时间戳差值
            Long dLong =  overTime.getTime() - initTime.getTime();
            if (60000l>dLong&&dLong>1000l){
                xyRemind.setOverConsumTime("0时0分"+dLong/1000+"秒");
            }else {
                if(60000*60l>dLong&&dLong>60000){
                    xyRemind.setOverConsumTime("0时"+dLong/1000/60+"分");
                }else {
                    xyRemind.setOverConsumTime(""+dLong/1000/60/60+"小时");
                }
            }
        }
        Boolean result= xyRemindService.updateXyRemindInfo(xyRemind);
        return new SimpleCoreResponse("200","查询成功" ,result);
    }
}

